﻿using System;
using System.ComponentModel;

namespace Mss.Common.Helpers
{
    /// <summary>
    /// Implements <see cref="INotifyPropertyChanged"/>.
    /// </summary>
    public class NotifyPropertyChangedBase : INotifyPropertyChanged, IDisposable
    {
        #region IDisposable Members

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <filterpriority>2</filterpriority>
        public virtual void Dispose()
        {
            PropertyChanged = null;
        }

        #endregion

        #region INotifyPropertyChanged Members

        /// <summary>
        /// Occurs when a property value changes.
        /// </summary>
        [field: NonSerialized]
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        /// <summary>
        /// Raise <see cref="PropertyChanged"/>  event.
        /// </summary>
        /// <param name="propertyName">Property Name</param>
        protected void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this,
                        new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}